package database

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"shopAdd-srv/global"
	"shopAdd-srv/internal/model"
)

var err error

func Mysql() {

	MysqlConfig := global.Config.Mysql

	// 参考 https://github.com/go-sql-driver/mysql#dsn-data-source-name 获取详情
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local",
		MysqlConfig.User,
		MysqlConfig.Password,
		MysqlConfig.Host,
		MysqlConfig.Port,
		MysqlConfig.Database)
	global.DB, err = gorm.Open(mysql.Open(dsn))
	global.DB.AutoMigrate(&model.Shop{})
}
